/************************************************************************
 * <br>
 * <ul>
 * <li>版权所有：唐山弘川科技有限公司 2009－2020</li>
 * <li>创建日期：2009-8-4</li>
 * <li>初始作者：刘川</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 ***********************************************************************/
/*package com.hy.enterprise.framework.util.seam ;

import java.lang.reflect.Method;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.jboss.seam.Component;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
import org.jboss.seam.util.EJB;

import com.vsoft.libra.enterprise.framework.util.jpa.EntityScanner;
import com.vsoft.libra.enterprise.framework.util.lang.AnnotationUtil;
import com.vsoft.libra.enterprise.framework.util.logger.SeamLoggerUtil;

*//**
 * <ul>
 * <li>设计作者：刘川</li>
 * <li>设计日期：2009-8-4</li>
 * <li>设计时间：下午01:00:47</li>
 * <li>设计目的：Seam操作助手类</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 *//*
public class SeamUtil
{
	*//**
	 * 日志记录器
	 *//*
	private static LogProvider	logger	=
	                                      Logging
	                                             .getLogProvider ( SeamUtil.class ) ;

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-4</li>
	 * <li>设计时间：下午01:04:10</li>
	 * <li>设计目的：获取指定Seam组件实例的类型</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param component
	 * @return
	 *//*
	public static Class < ? > getComponentType (
	                                             final Component component )
	{
		Class < ? > clazz =
		                    null ;

		if ( component
		              .getType ( )
		              .isSessionBean ( )
		     && ( component
		                   .getBusinessInterfaces ( )
		                   .size ( ) > 0 ) )
		{
			for ( Class < ? > tempComponent : component
			                                           .getBusinessInterfaces ( ) )
			{
				if ( tempComponent
				                  .isAnnotationPresent ( EJB.LOCAL ) )
				{
					clazz =
					        tempComponent ;
					break ;
				}
			}

			if ( clazz == null )
			{
				throw new RuntimeException (
				                             String
				                                   .format (
				                                             "无法确定组件[%s]的类型。请确认该组件存在本地接口。" ,
				                                             component ) ) ;
			}
		}

		if ( clazz == null )
		{
			clazz =
			        component
			                 .getBeanClass ( ) ;
		}
		SeamLoggerUtil
		              .debug (
		                       SeamUtil.logger ,
		                       "所获取到的Seam组件的类型为：\n"
		                               + clazz ) ;
		return clazz ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-4</li>
	 * <li>设计时间：下午01:02:23</li>
	 * <li>设计目的：通过名称获取指定Seam组件的类型</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param componentName
	 * @return
	 *//*
	public static Class < ? > getComponentType (
	                                             String componentName )
	{
		Class < ? > result =
		                     null ;
		SeamLoggerUtil
		              .debug (
		                       SeamUtil.logger ,
		                       "SeamUtil.getComponentType( "
		                               + componentName
		                               + ")所需要获取类型的Seam组件的类型名称为："
		                               + componentName ) ;
		if ( componentName != null )
		{
			Component component =
			                      Component
			                               .forName ( componentName ) ;
			SeamLoggerUtil
			              .debug (
			                       SeamUtil.logger ,
			                       "SeamUtil.getComponentType( "
			                               + componentName
			                               + ")内部，通过Component.forName( "
			                               + componentName
			                               + " )方式所获取到的Seam组件实例为：\n"
			                               + ToStringBuilder
			                                                .reflectionToString (
			                                                                      component ,
			                                                                      ToStringStyle.MULTI_LINE_STYLE ) ) ;
			if ( component != null )
			{
				result =
				         SeamUtil
				                 .getComponentType ( component ) ;
				SeamLoggerUtil
				              .debug (
				                       SeamUtil.logger ,
				                       "SeamUtil.getComponentType( "
				                               + componentName
				                               + ")内部，通过SeamUtil.getComponentType( "
				                               + component
				                               + " )方式所获取到的Seam组件实例为：\n"
				                               + ToStringBuilder
				                                                .reflectionToString (
				                                                                      result ,
				                                                                      ToStringStyle.MULTI_LINE_STYLE ) ) ;
			}
		}
		return result ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-4</li>
	 * <li>设计时间：下午01:11:04</li>
	 * <li>设计目的：通过名称和组件实例获取指定Seam组件的类型</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param componentName
	 * @param targetInstance
	 * @return
	 *//*
	public static Class < ? > getComponentType (
	                                             String componentName ,
	                                             Object targetInstance )
	{
		Class < ? > targetClass =
		                          null ;
		// 1.
		targetClass =
		              SeamUtil
		                      .getComponentType ( componentName ) ;
		SeamLoggerUtil
		              .debug (
		                       SeamUtil.logger ,
		                       "通过SeamUtil.getComponentType ( "
		                               + componentName
		                               + " )方法所获取到的Seam组件实例为：\n"
		                               + targetClass ) ;
		// 2.
		if ( ( targetClass == null )
		     && ( targetInstance != null ) )
		{
			targetClass =
			              targetInstance
			                            .getClass ( ) ;
			SeamLoggerUtil
			              .debug (
			                       SeamUtil.logger ,
			                       "targetInstance.getClass ( )方法所获取到的Seam组件实例为：\n"
			                               + targetClass ) ;
		}
		// 3.
		if ( targetClass == null )
		{
			try
			{
				targetClass =
				              EntityScanner
				                           .instance ( )
				                           .getEntity (
				                                        componentName ) ;
				SeamLoggerUtil
				              .debug (
				                       SeamUtil.logger ,
				                       "通过EntityScanner.instance ( ).getEntity ( "
				                               + componentName
				                               + " )方法所获取到的Seam组件实例为：\n"
				                               + targetClass ) ;
			}
			catch ( ClassNotFoundException classNotFoundException )
			{
				// 不做任何事情
			}
		}
		return targetClass ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-4</li>
	 * <li>设计时间：下午01:37:51</li>
	 * <li>设计目的：判断指定名称的Seam组件中是否存在指定名称的方法</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param componentName
	 * @param methodName
	 * @return
	 *//*
	public static boolean isMethodPresentInClass (
	                                               String componentName ,
	                                               String methodName )
	{
		boolean isExist =
		                  false ;

		Component component =
		                      Component
		                               .forName ( componentName ) ;
		Class < ? > seamComponentClass =
		                                 component
		                                          .getBeanClass ( ) ;

		for ( Method seamComponentMethod : seamComponentClass
		                                                     .getDeclaredMethods ( ) )
		{
			if ( seamComponentMethod
			                        .getName ( )
			                        .equals (
			                                  methodName ) )
			{
				isExist =
				          true ;
				break ;
			}
		}

		return isExist ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：上午11:27:58</li>
	 * <li>设计目的：判断给定类型是否为Seam组件</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param clazz
	 * @return
	 *//*
	public static boolean isSeamComponent (
	                                        Class < ? > clazz )
	{
		return AnnotationUtil
		                     .isClassAnnotationPresent (
		                                                 clazz ,
		                                                 Name.class ) ;
	}

	*//**
	 * <ul>
	 * <li>设计作者：刘川</li>
	 * <li>设计日期：2009-8-14</li>
	 * <li>设计时间：上午11:30:18</li>
	 * <li>设计目的：判断给定对象是否为Seam组件实例</li>
	 * </ul>
	 * <ul>
	 * <b>修订历史</b>
	 * <li>1、</li>
	 * </ul>
	 * 
	 * @param object
	 * @return
	 *//*
	public static boolean isSeamComponent (
	                                        Object object )
	{
		if ( null == object )
		{
			return false ;
		}
		else
		{
			return SeamUtil
			               .isSeamComponent ( object
			                                        .getClass ( ) ) ;
		}
	}

	*//**
	 * 构造函数
	 *//*
	private SeamUtil ( )
	{
		super ( ) ;
	}
}*/
